package com.houzehui.product.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.houzehui.product.entity.SpecGroup;
import com.houzehui.product.entity.SpecParam;
import com.houzehui.product.mapper.SpecParamMapper;
import com.houzehui.product.service.ISpecParamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.houzehui.product.vo.SpecParamVo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 规格参数组下的参数名 服务实现类
 * </p>
 *
 * @author houzehui
 * @since 2022-04-27
 */
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements ISpecParamService {

    @Override
    public List<SpecParam> getSpecParam(Long cid,Long group) {
        List<SpecParam> specParams = list(new QueryWrapper<SpecParam>().eq("cid",cid).eq("group_id", group));
        return specParams;
    }

    private SpecParamVo toSpecParamVo(SpecParam specParam){
        SpecParamVo specParamVo = new SpecParamVo();
        BeanUtil.copyProperties(specParam,specParamVo);
        return specParamVo;
    }

    @Override
    public List<SpecParamVo> getSpecParamVo(Long cid,Long group) {
        List<SpecParam> specParam = getSpecParam(cid,group);

        ArrayList<SpecParamVo> specParamVos = new ArrayList<>();
        specParam.forEach(specParam1 -> {
            SpecParamVo specParamVo = toSpecParamVo(specParam1);
            specParamVos.add(specParamVo);
        });
        return specParamVos;
    }

}
